import { R_tableData, R_add, R_update, R_remove } from "@/utils/tableData";

import request from '@/utils/request'

import { Message } from 'element-ui'


export const A_tableData = function(data) {
    return R_tableData({
        method: 'post',
        url: '/UserManage/list',
        data: data,

    })
}

export const A_add = function(data) {
    return R_add({
        method: 'post',
        url: '/UserManage/add',
        data: data

    })
}

export const A_update = function(data) {
    return R_update({
        method: 'post',
        url: '/UserManage/update',
        data: data
    })
}

export const A_remove = function(ID) {
    return R_remove({
        method: 'post',
        url: '/UserManage/delete',
        data: {
            userId: ID
        }
    })
}

/**
 * 添加权限
 * @param {*} data userKey,rootName
 */
export const A_addRoot = async function(data) {
    let result = request({
        method: 'post',
        url: '/UserManage/addRoot',
        data
    })
    return result
}


/**
 * 删除权限
 * @param {*} data userKey,rootName
 */
export const A_removeRoot = async function(data) {
    let result = await request({
        method: 'post',
        url: '/UserManage/DeleteRoot',
        data
    })
    return result
}


/**
 * 下载表格
 * @param {*} data 
 * @returns 
 */
export const A_downLoadExcel = async function(data) {
    let res = await request({
        method: 'post',
        url: '/UserManage/downLoadExcel',
        data,
        headers: {
            "Content-Type": 'application/octet-stream;charset=UTF-8'
        },
        responseType: 'blob'
    })
    return res
}

export const A_downLoadExample = async function() {
    let res = await request({
        method: 'get',
        url: '/UserManage/downLoadExcelExample',
        headers: {
            "Content-Type": 'application/octet-stream;charset=UTF-8'
        },
        responseType: 'blob'
    })
    return res
}